package com.example.lt.service.video.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.lt.entity.video.Type;
import com.example.lt.mapper.video.TypeMapper;
import com.example.lt.service.video.TypeService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @Author 小涛Tao
 * @Date: 2024/08/03/21:24
 * version 1.0 注释：
 **/
@Service
public class TypeServiceImpl extends ServiceImpl<TypeMapper, Type> implements TypeService {

    /**
     * 随机获取10个所有分类下的标签
     * @return 标签集合
     */
    @Override
    public List<String> random10Labels() {
        final List<Type> types = list(null);
        Collections.shuffle(types);
        final ArrayList<String> labels = new ArrayList<>();
        for (Type type : types) {
            for (String label : type.buildLabel()) {
                if (labels.size() == 10) {
                    return labels;
                }
                labels.add(label);
            }
        }
        return labels; // 说明分类中的标签较少，少于10个
    }

}
